﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace ARMS.BaseClasses
{
    public class Helper
    {
        internal static int DummyValue = -1;
    }

    public class ARMSConverter
    {
        public static string DateTimeToString(DateTime datetime)
        {
            try
            {
                return String.Format("{0:yyyy-MM-ddThh:mm:ssZ}", datetime);
            }
            catch (Exception e)
            {
                throw new Exception(String.Format("Invalid datetime stamp {0}", datetime.ToString()),e);
            }
        }
        public static string DSToString(DateTime datetime)
        {
            
            try
            {
                string value = String.Format("{0:yyyy-MM-ddThh:mm:ssZ}", datetime);
                return value;
            }
            catch (Exception e)
            {
                throw new Exception(String.Format("Invalid datetime stamp {0}", datetime.ToString()),e);
            }

        }

        public static DateTime ToDateTime(string value, bool hideException)
        {
            DateTime dateTime = DateTime.Now;
            try
            {
                if (value != null) 
                    dateTime = Convert.ToDateTime(value);
            }
            catch (Exception e)
            {
                if (!hideException)
                    throw new Exception(String.Format("Invalid date time {0}", value), e);
            }
            return dateTime;
        }

        public static int ToInt(string value, int newValue, bool hideException)
        {
            int result = newValue;
            try
            {
                result = Convert.ToInt16(value);
            }
            catch (Exception e)
            {
                if (!hideException)
                    throw new Exception(String.Format("Invalid number {0}", value), e);
            }
            return result;
        }
    }
}